package com.day4.serializedev.impl;

import com.alibaba.fastjson.JSON;
import com.day4.serializedev.Serializer;
import com.day4.serializedev.SerializerAlogrithm;

/**
 * @author leonard
 * @Description
 * @date 2021-05-24 12:37
 */
public class JSONSerializer implements Serializer {
    @Override
    public byte getSerializerAlgorithm() {
        return SerializerAlogrithm.JSON;
    }

    @Override
    public byte[] serialze(Object object) {
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserialze(Class<T> clazz, byte[] bytes) {
        return JSON.parseObject(bytes,clazz);
    }
}
